#ifndef MYWEBVIEW_H
#define MYWEBVIEW_H

#include "pch.h"
#include <mynetworkaccessmanager.h>
#include <javascriptapi.h>

class myWebInspector : public QWebInspector
{
    Q_OBJECT
signals:
    void shEvent(bool);
public:
    myWebInspector(QWidget* parent = 0);

protected:
    void showEvent(QShowEvent* event);
    void hideEvent(QHideEvent* event);
};

class myWebPage : public QWebPage
{
    Q_OBJECT

signals:

public:
    myWebPage(QObject *parent = 0);
    QString getUserAgent() { return userAgent; }
    void InspectElement();

public slots:

private:
    bool acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest &request, NavigationType type);
    int DownloadFile(const QUrl &url);
    friend class myWebView;
    QString userAgent;

    JavaScriptApi *m_JSApi;

protected slots:
    void handleUnsupportedContent(QNetworkReply *reply);
    void addExternalBinding(QWebFrame *frame = 0);

protected:
    QString userAgentForUrl(const QUrl&) const;
};

class myWebView : public QWebView
{
    Q_OBJECT
public:
    myWebView(QWidget *parent = 0);
    myWebPage *webPage() const { return m_page; }
    void load(const QUrl &url);

signals:
    void signalOpenLinkInNewTab(const QUrl &url);

private slots:
    void openLinkInNewTab();
    void downloadRequested(const QNetworkRequest &request);

protected:
    void contextMenuEvent(QContextMenuEvent *event);
    void mousePressEvent(QMouseEvent *);

private:
    myWebPage *m_page;
    bool isUrlValid(const QUrl &url);
    QUrl *newTabUrl;
    myNetworkAccessManager *m_networkAccessManager;
};

#endif // MYWEBVIEW_H
